import { reqLbgg } from '@/apis/index.js';
import { errorReport, getMarketInfoTable } from '@/scripts/tools.js';
export default {
  methods: {
    getLbgg({ noticeData, tableDataName, columnsName }, callback) {
      reqLbgg()
        .then(res => {
          const tableData = [];
          // 所有的股票代码，给客户端协议使用
          const stockcodes = [];
          // 所有的市场代码，给客户端协议使用
          const markets = [];
          res.data.forEach(item => {
            const { stockcode, stockname, ztgl, ztyy, marketcode, date, stockContinueLimitUpDays } = item;
            tableData.push({
              stockName: stockname,
              stockCode: stockcode,
              rise: '',
              price: '',
              acceleration: '',
              chance: ztgl,
              plate: stockContinueLimitUpDays,
              reason: ztyy,
              date: date,
              market: marketcode,
              notice: noticeData && !!noticeData.find(i => i.stockCode === item.stockcode),
            });
            stockcodes.push(stockcode);
            markets.push(marketcode);
          });
          getMarketInfoTable({ stockcodes, marketids: markets, tableData }).then(resTable => {
            this[tableDataName] = resTable;
            this.sortData(this[columnsName], tableDataName);
            callback && callback();
          });
        })
        .catch(err => {
          errorReport({
            name: `接口获取连板个股错误,${err.name}`,
            message: err.message,
            stack: err.stack,
          });
        });
    },
  },
};
